#ifndef __FREE_NEHE_H__
#define __FREE_NEHE_H__

//FreeType Headers
#include <ft2build.h>
#include <freetype/freetype.h>
#include <freetype/ftglyph.h>
#include <freetype/ftoutln.h>
#include <freetype/fttrigon.h>

//OpenGL Headers 
#include <GL/gl.h>
#include <GL/glu.h>

//Using the STL exception library increases the
//chances that someone else using our code will corretly
//catch any exceptions that we throw.
#include <stdexcept>


///Wrap everything in a namespace, that we can use common
///function names like "print" without worrying about
///overlapping with anyone else's code.
namespace FontHelper{

    template<typename T> 
        class Singleton {
            private:
                Singleton(const Singleton<T> &);
                Singleton& operator= (const Singleton<T> &);

            protected:
                static T *m_sigleton;

            public:
                Singleton(void) {
                    m_sigleton = static_cast<T*>(this);
                }

                ~Singleton() {
                    m_sigleton = 0;
                }

                static T& getSingleton(void) {
                    return *m_sigleton;
                }

                static T* getSingletonPtr(void) {
                    return m_sigleton;
                }
        };

    //这个类保存着根据freetype font而创建的信息
    struct FontData {
        float h;			// 字体的高度
        GLuint *textures;	// 纹理编号
        GLuint list_base;	// 第一个显示列表ID

        //从字体文件名中创建指定高度的字体
        void init(const char * fname, unsigned int h);

        //释放所有字体相关资源
        void clean();
    };

    /*******************实用工具*********************/ 
    //给定一个数，返回大于它的最小的2的指数
    inline int next_p2(int a) {
        int rval = 1;
        while (rval < a) rval <<= 1;
        return rval;
    }

    class FontManager : public Singleton<FontManager> {
        public:
            //使用字体ft_font在屏幕坐标x,y处打印字符串,模型视图矩阵将会影响字符串
            void print(const FontData &ft_font, float x, float y, const char *fmt, ...) ;

    };
}

#endif
